package com.pureut.production.controller;


import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.production.domain.PublicScheduling;
import com.pureut.production.domain.dto.PdaDto;
import com.pureut.production.domain.dto.ScFqDto;
import com.pureut.production.domain.dto.SpunlaceOrderDto;
import com.pureut.production.domain.vo.*;
import com.pureut.production.service.SpunlaceOrderService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: CM
 * @date: 2023/2/9  11:22
 */
@RestController
@RequestMapping("/spunlaceOrder")
public class SpunlaceOrderController extends BaseController {

    @Resource
    private SpunlaceOrderService spunlaceOrderService;

    /**
     * 停产
     */
    @RequiresPermissions("productionTube:produAdm:spunlace:preparaorder:stop")
    @Log(title = "停产", businessType = BusinessType.UPDATE)
    @PutMapping("/ldle")
    public AjaxResult ldle(@Validated @RequestBody SpunlaceOrderVo spunlaceOrderVo) {
        return toAjax(spunlaceOrderService.ldle(spunlaceOrderVo));
    }

    /**
     * 复产
     */
    @RequiresPermissions("productionTube:produAdm:spunlace:preparaorder:resurrection")
    @Log(title = "复产", businessType = BusinessType.UPDATE)
    @PutMapping("/prolific")
    public AjaxResult prolific(@RequestBody SpunlaceOrderVo spunlaceOrderVo) {
        return toAjax(spunlaceOrderService.prolific(spunlaceOrderVo));
    }


    /**
     * 关结
     */
    @RequiresPermissions("productionTube:produAdm:spunlace:preparaorder:close")
    @Log(title = "关结", businessType = BusinessType.UPDATE)
    @PutMapping("/close")
    public AjaxResult close(@Validated @RequestBody SpunlaceOrderCloseVo spunlaceOrderCloseVo) {
        return toAjax(spunlaceOrderService.close(spunlaceOrderCloseVo));
    }

    /**
     * 水刺制令单列表查询
     */
    @RequiresPermissions("productionTube:produAdm:spunlace:preparaorder:list")
    @GetMapping("/list")
    public TableDataInfo getList(SpunlaceOrderVo spunlaceOrderVo) {
        startPage();
        //查询水刺制令单列表
        List<SpunlaceOrderDto> list = spunlaceOrderService.getList(spunlaceOrderVo);
        return getDataTable(list);
    }

    /**
     * 查看单据
     */
    @RequiresPermissions("productionTube:produAdm:spunlace:preparaorder:query")
    @GetMapping("/view/{id}")
    public AjaxResult view(@PathVariable("id") Long id) throws Exception {
        return AjaxResult.success(spunlaceOrderService.view(id));
    }

    /**
     * 关联工艺回显
     */
    @GetMapping("/processView")
    @RequiresPermissions("productionTube:produAdm:spunlace:preparaorder:relation")
    public AjaxResult processView(Long id) throws Exception {
        return AjaxResult.success(spunlaceOrderService.processView(id));
    }

    /**
     * 关联工艺保存
     */
    @Log(title = "关联工艺保存", businessType = BusinessType.INSERT)
    @PostMapping("/processSave")
    public AjaxResult processSave(@RequestBody PublicProcessVo publicProcessVo) {
        return toAjax(spunlaceOrderService.processSave(publicProcessVo));
    }

    /**
     * 工艺确认回显
     */
    @RequiresPermissions("productionTube:produAdm:spunlace:preparaorder:confirm")
    @GetMapping("/processAffirmView")
    public AjaxResult processAffirmView(Long id) throws Exception {
        return AjaxResult.success(spunlaceOrderService.processAffirmView(id));
    }

    /**
     * 工艺确认
     */
    @RequiresPermissions("productionTube:produAdm:spunlace:preparaorder:confirm")
    @Log(title = "工艺确认", businessType = BusinessType.UPDATE)
    @PostMapping("/processAffirm")
    public AjaxResult processAffirm(@RequestBody PublicProcessVo publicProcessVo) {
        return toAjax(spunlaceOrderService.processAffirm(publicProcessVo));
    }

    @Log(title = "新增水刺分切制令单", businessType = BusinessType.INSERT)
    @PostMapping("/addOrderCut")
    public int addOrderCutScheduling(@RequestBody PublicScheduling publicScheduling) throws Exception {
        return spunlaceOrderService.addOrderCutScheduling(publicScheduling);
    }


    /**
     * 新增水刺制令单，分切制令单
     */
    /*
    @Log(title = "新增水刺分切制令单", businessType = BusinessType.INSERT)
    @PostMapping("/addOrderCut")
    public AjaxResult addOrderCut(@RequestBody PublicProcessVo publicProcessVo) {
        return toAjax(spunlaceOrderService.addOrderCut(publicProcessVo));
    }
    */


    /**
     * 水刺制令单和分切制令单列表
     */
    @GetMapping("/getMoOrderList")
    public AjaxResult getMoOrderList(String moNumber) {
        //查询水刺制令单列表
        List<ScFqDto> list = spunlaceOrderService.getMoOrderList(moNumber);
        return AjaxResult.success(list);
    }

    /**
     * 水刺制令单和脱脂制令单列表
     */
    @GetMapping("/getMoSpunlaceAndDegrease")
    public AjaxResult getMoSpunlaceAndDegrease(String productionLine) {
        //查询水刺制令单列表
        List<ScFqDto> list = spunlaceOrderService.getMoSpunlaceAndDegrease(productionLine);
        return AjaxResult.success(list);
    }



    /**
     * feign级调用，品质在配置检验方案之后修改指令单的单据状态
     *
     * @param editQualityOrderVo
     * @return
     * @throws Exception
     */
    @PostMapping("/editQualityOrder")
    public boolean editQualityOrder(@RequestBody EditQualityOrderVo editQualityOrderVo) throws Exception {
        return spunlaceOrderService.editQualityOrder(editQualityOrderVo);
    }

    /**
     * 仓库条码打印
     */
    @GetMapping("/getProductionNumberPrint")
    public AjaxResult getProductionNumber(String materialNumber, String type) {
        //查询仓库条码
        return AjaxResult.success(spunlaceOrderService.getProductionNumberPrint(materialNumber, type));
    }

    /**
     * 查询工艺卡编码（远程调用 产品追溯页面）
     */
    @GetMapping("/getProcessCardCoding")
    public AjaxResult getProcessCardCoding(String wsiConnectNum) {
        //查询仓库条码
        return AjaxResult.success(spunlaceOrderService.getProcessCardCoding(wsiConnectNum));
    }

    /**
     * 标签绑定接口
     */
    @Log(title = "标签绑定", businessType = BusinessType.INSERT)
    @RequiresPermissions("productionTube:produAdm:spunlace:preparaorder:binding")
    @PostMapping("/savePrintTemplete")
    public AjaxResult savePrintTemplete(@RequestBody PrintTempleteVo printTempleteVo) {
        return toAjax(spunlaceOrderService.savePrintTemplete(printTempleteVo));
    }

    /**
     * 水刺产出（生产中和停产列表）
     */
    @GetMapping("/getPdaList")
    public TableDataInfo getPdaList(PdaVo pdaVo) {
        startPage();
        List<PdaDto> pdaList = spunlaceOrderService.getPdaList(pdaVo);
        return getDataTable(pdaList);
    }

    /**
     * 根据关联单号查询水刺投料信息
     *
     * @param materialNumber
     * @return
     */
    @GetMapping("/selectSpunlaceOrderInfo")
    public AjaxResult selectSpunlaceOrderInfo(String materialNumber) {
        return AjaxResult.success(spunlaceOrderService.selectSpunlaceOrderInfo(materialNumber));
    }

    /**
     * 根据关联单号查询水刺制令单信息
     *
     * @param feedOrderNumber
     * @return
     */
    @GetMapping("/selectDocumentStatusInfo")
    public AjaxResult selectDocumentStatusInfo(String feedOrderNumber) {
        return AjaxResult.success(spunlaceOrderService.selectDocumentStatusInfo(feedOrderNumber));
    }

    /**
     * 根据生产计划单号查询水刺制令单数据(生产排程退回调用fegin)
     */
    @GetMapping("/getStatusByPlanNumber")
    public boolean getStatusByPlanNumber(String planNumber) {
        return spunlaceOrderService.getStatusByPlanNumber(planNumber);
    }

    /**
     * 删除水刺制令单
     */
    @DeleteMapping("/removeMoNumber")
    public boolean remove(String planNumber){
        return spunlaceOrderService.remove(planNumber);
    }


}
